<template>
  <div class="app-container">
    <br>
    <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
      <el-table-column
          align="center"
          prop="id"
          width="100"
          label="ID">
      </el-table-column>
      <el-table-column
          align="center"
          prop="username"
          label="用户">
      </el-table-column>
      <el-table-column
          align="center"
          prop="order_id"
          label="订单">
      </el-table-column>
      <el-table-column prop="goodsImg" label="订单图片" align="center"  width="200" >
        <template #default="scope">
          <el-image :src="scope.row.goodsImg" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column
          align="center"
          prop="goodsName"
          label="订单名称">
      </el-table-column>
      <el-table-column
          align="center"
          prop="goodsMoney"
          label="订单金额">
      </el-table-column>
      <el-table-column
          align="center"
          prop="order_time"
          label="订单时间">
      </el-table-column>
      <el-table-column
          align="center"
          prop="status"
          label="订单状态"
      >
        <template #default="scope">
          <el-button v-if="scope.row.status==0" type="primary" size="mini">待付款</el-button>
          <el-button v-if="scope.row.status==1" type="warning" size="mini">待发货</el-button>
          <el-button v-if="scope.row.status==2" type="danger" size="mini">待收货</el-button>
          <el-button v-if="scope.row.status==3" type="danger" size="mini">已完成</el-button>
          <el-button v-if="scope.row.status==4" type="danger" size="mini">已取消</el-button>
        </template>
      </el-table-column>
      <el-table-column
          align="center"
          label="操作"
      >
        <template #default="scope">
          <el-button v-show="scope.row.status==1" @click="updateOrder(scope.row)">去发货</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

  </div>
</template>

<script>
import {getOrderList,updateOrder} from "@/api/MyOrder";


export default {
  name: "College",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      tableData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      queryParams: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    updateOrder(row){
      this.form.id=row.id;
      this.form.status=2;
      updateOrder(this.form).then(res=>{
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success'
        });
      })
    },

    handleSelectionChange() {
    },

    /*,* 查询【请填写功能名称】列表 */
    getList() {
      getOrderList().then(res => {
        this.tableData = res.data;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>

